#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/6/22 22:03
# @USER    : Shengji He
# @File    : AddBinary.py
# @Software: PyCharm
# @Version  : Python-
# @TASK:

class Solution:
    def addBinary(self, a: str, b: str) -> str:
        """
        Given two binary strings, return their sum (also a binary string).

        The input strings are both non-empty and contains only characters 1 or 0.

        Example 1:
            Input: a = "11", b = "1"

            Output: "100"
        Example 2:
            Input: a = "1010", b = "1011"

            Output: "10101"

        Constraints:
            - Each string consists only of '0' or '1' characters.

            - 1 <= a.length, b.length <= 10^4

            - Each string is either "0" or doesn't contain any leading zero.

        :param a:
        :param b:
        :return:
        """
        # if len(a) > len(b):
        #     b = '0' * (len(a) - len(b)) + b
        # else:
        #     a = '0' * (len(b) - len(a)) + a
        # idx = len(a) - 1
        # ans = []
        # carry = 0
        # while idx >= 0:
        #     if a[idx] == '1' and b[idx] == '1':
        #         if carry == 0:
        #             ans.insert(0, '0')
        #         else:
        #             ans.insert(0, '1')
        #         carry = 1
        #     elif a[idx] == '1' or b[idx] == '1':
        #         if carry == 0:
        #             ans.insert(0, '1')
        #         else:
        #             ans.insert(0, '0')
        #     else:
        #         if carry == 0:
        #             ans.insert(0, '0')
        #         else:
        #             ans.insert(0, '1')
        #             carry = 0
        #     idx -= 1
        # if carry == 1:
        #     ans.insert(0, '1')
        #
        # return ''.join(ans)
        return '{0:b}'.format(int(a, 2) + int(b, 2))


if __name__ == '__main__':
    S = Solution()
    a = '1010'
    b = '1011'
    print(S.addBinary(a, b))
    print('done')
